home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cdbmang.exe / TEST.C < prev    next >
Text File  |  1991-05-20  |  5KB  |  151 lines

  1. /*
  2.  *  TEST.C
  3.  *
  4.  *  Important:
  5.  *
  6.  *  This test program will only provide an example of how the CDB API is
  7.  *  used.  Nothing will be displayed as a result of executing this module.
  8.  *
  9.  *  This program will add 3 customer records to the TEST database.
  10.  *  Associated with each customer is an address record or records.  Each
  11.  *  customer added will have at least 1 address record as a member.  After
  12.  *  these records are added and the set connections are made, the program
  13.  *  will use variations of CDB calls to retrieve these records.
  14.  *
  15.  *  This program is intended to be executed with a source level debugger.
  16.  *  After each CDB call, display the status value returned.  Also, in
  17.  *  cases where a record is being retrieved, display a dump of the record
  18.  *  contents.  This will help you understand what is accomplished with
  19.  *  each function call.
  20.  *
  21.  *  We are currently working on a fully functional application that uses
  22.  *  CDB to give to our users as an example.
  23.  *
  24.  *
  25.  *  Copyright (C) 1991 by Daytris.  All rights reserved.
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include "dbmgr.h"
  31. #include "test.h"
  32.  
  33. int main( int argc, char **argv);
  34. void DbError( INT status, INT lineNbr);
  35.  
  36.  
  37. struct customer customer[3] =
  38.     {
  39.     {1000L,"Daytris",0.00},
  40.     {1001L,"CompuServe",0.00},
  41.     {1002L,"Microsoft",0.00},
  42.     };
  43.  
  44. struct address address[4] =
  45.     {
  46.     {"81 Bright Street, Suite 1E","Jersey City","NJ","07302","2012000018"},
  47.     {"2000 Arlington Center Blvd","Columbus","OH","43228","6144598600"},
  48.     {"12 North Fork Ave.","Redmond","WA","55555","5332341234"},
  49.     {"13 North Fork Ave.","Redmond","WA","55555","5332341235"},
  50.     };
  51.  
  52.  
  53. int main( int argc, char *argv[])
  54.     {
  55.     INT status;
  56.     long acctNbr = 1001L;
  57.     struct currency_index currency;
  58.     struct customer t_customer;
  59.     struct address t_address;
  60.  
  61.     /* Open the database */
  62.     if( status = DbOpen( ".\\", "test.dbd"))
  63.         {
  64.         printf( "Error (%d) opening test.dbd\n", status);
  65.         exit( 1);
  66.         }
  67.  
  68.     /* Customer 1000 */
  69.     if( status = DbRecordAdd( "customer", &customer[0]))
  70.         DbError( status, __LINE__);
  71.     if( status = DbRecordAdd( "address", &address[0]))
  72.         DbError( status, __LINE__);
  73.     if( status = DbSetAdd( "customer", "address"))
  74.         DbError( status, __LINE__);
  75.  
  76.     /* Customer 1001 */
  77.     if( status = DbRecordAdd( "customer", &customer[1]))
  78.         DbError( status, __LINE__);
  79.     if( status = DbRecordAdd( "address", &address[1]))
  80.         DbError( status, __LINE__);
  81.     if( status = DbSetAdd( "customer", "address"))
  82.         DbError( status, __LINE__);
  83.  
  84.     /* Customer 1002 */
  85.     if( status = DbRecordAdd( "customer", &customer[2]))
  86.         DbError( status, __LINE__);
  87.     if( status = DbRecordAdd( "address", &address[2]))
  88.         DbError( status, __LINE__);
  89.     if( status = DbSetAdd( "customer", "address"))
  90.         DbError( status, __LINE__);
  91.     if( status = DbRecordAdd( "address", &address[3]))
  92.         DbError( status, __LINE__);
  93.     if( status = DbSetAdd( "customer", "address"))
  94.         DbError( status, __LINE__);
  95.  
  96.     /* Get the first customer by account number */
  97.     if( status = DbRecordFindFirst( "customer", "acctNbr"))
  98.         DbError( status, __LINE__);
  99.     if( status = DbRecordGetCurrent( "customer", &t_customer))
  100.         DbError( status, __LINE__);
  101.  
  102.     /* Save the currency */
  103.     if( status = DbRecordGetCurrency( "customer", ¤cy))
  104.         DbError( status, __LINE__);
  105.  
  106.     /* Get the last customer */
  107.     if( status = DbRecordGetLast( "customer", "acctNbr", &t_customer))
  108.         DbError( status, __LINE__);
  109.  
  110.     /* Get the addresses */
  111.     if( status = DbSetFindFirst( "customer", "address"))
  112.         DbError( status, __LINE__);
  113.     if( status = DbSetGetFirst( "customer", "address", &t_address))
  114.         DbError( status, __LINE__);
  115.     if( status = DbSetGetNext( "customer", "address", &t_address))
  116.         DbError( status, __LINE__);
  117.  
  118.     /* Restore the customer currency and retrieve the current customer */
  119.     if( status = DbRecordUpdCurrency( "customer", ¤cy))
  120.         DbError( status, __LINE__);
  121.     if( status = DbRecordGetCurrent( "customer", &t_customer))
  122.         DbError( status, __LINE__);
  123.  
  124.     /* Get customer 1001 */
  125.     if( status = DbRecordGetByKey( "customer", "acctNbr", &t_customer, &acctNbr))
  126.         DbError( status, __LINE__);
  127.  
  128.     /* Get address */
  129.     if( status = DbRecordGetByKey( "address", "zip", &t_address, "55555"))
  130.         DbError( status, __LINE__);
  131.  
  132.     /* Get the owner of the address */
  133.     if( status = DbSetGetOwner( "customer", "address", &t_customer))
  134.         DbError( status, __LINE__);
  135.  
  136.     if( status = DbFlush())
  137.         DbError( status, __LINE__);
  138.     if( status = DbClose())
  139.         DbError( status, __LINE__);
  140.  
  141.     return status;
  142.     }
  143.  
  144.  
  145. void DbError( INT status, INT lineNbr)
  146.     {
  147.     printf( "File: %s, Line: %d, Database Error: %d\n", __FILE__, lineNbr,
  148.         status);
  149.     exit( status);
  150.     }
  151.